package com.own.business.comment.entity.vo;

import com.own.business.comment.entity.po.Comment;
import com.own.component.common.base.entity.vo.BaseVo;
import com.own.constant.ConstantBeanSuffix;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * CommentVo
 *
 * @author chenxueli
 * @date 2023-07-03 14:15:52
 */
@Schema(title = "评论" + ConstantBeanSuffix.VO)
@Getter
@Setter
@ToString
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
public class CommentVo extends BaseVo<Comment> implements Serializable {

    @Schema(title = "评论用户id")
    private Long userId;

    @Schema(title = "评论目标id")
    private Long targetId;

    @Schema(title = "主要内容")
    private String content;

    @Schema(title = "评论上级id")
    private Long commentId;

    @Schema(title = "最初的评论id")
    private Long rootCommentId;

    @Schema(title = "评论等级")
    private Integer level;

    /**
     * 构造方法
     *
     * @param entity 原对象
     */
    public CommentVo(@NonNull Comment entity) {
        super(entity);
        this.userId = entity.getFkUserId();
        this.targetId = entity.getFkTargetId();
        this.content = entity.getContent();
        this.commentId = entity.getFkCommentId();
        this.rootCommentId = entity.getRootCommentId();
        this.level = entity.getLevel();
    }

    /**
     * 转po对象
     *
     * @param entity 原对象
     * @return po对象
     */
    @Override
    public Comment toPo(Comment entity) {
        if (entity == null) {
            entity = new Comment();
        }
        entity.setFkUserId(this.userId);
        entity.setFkTargetId(this.targetId);
        entity.setContent(this.content);
        entity.setFkCommentId(this.commentId);
        entity.setRootCommentId(this.rootCommentId);
        entity.setLevel(this.level);
        return super.toPo(entity);
    }

}
